# 定义初始端口号
port=81

# 向nginx的default.conf文件中添加server配置
config_file="/app/nginx/default.conf"

# 创建新的server配置块
server_block="
server {
    listen       $port;
    listen  [::]:$port;
    server_name  localhost;

    location / {
        proxy_pass http://192.168.5.105:3001/;
        proxy_set_header Host \$host:\$server_port;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
"
# 检查default.conf文件中是否已经存在指定端口的配置
if grep -q "listen\s*$port;" "$config_file"; then
    echo "Port $port is already configured in $config_file."
else
    # 如果不存在，则将新的server配置块添加到文件末尾
    echo "$server_block" >> "$config_file"
    echo "Added server block for port $port to $config_file."
fi
docker restart nginx